#include "spawner.h"
#include "enemy.h"
#include "world/effect.h"
#include "core/scene.h"

void Spawner::update(float dt)
{
    if (!target_ || !target_->getActive()) return;
    timer_ += dt;
    if (timer_ >= interval_) {
        timer_ = 0;
        game.playSound("assets/sound/silly-ghost-sound-242342.mp3");
        for(int i=0; i<num_; i++) {
            // spawn enemy
            auto pos = game.randomVec2( game.getCurrentScene()->getCameraPosition(), 
                                        game.getCurrentScene()->getCameraPosition() + game.getScreenSize());
            Enemy* enemy = Enemy::addEnemychild(nullptr, pos, target_);
            Effect::addEffectChild(game.getCurrentScene(), "assets/effect/184_3.png", pos, 1.0f, enemy);
        }
    }
}